<!DOCTYPE html>
<html>
{include file="public1/_header" /}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a>
                <cite>课程考勤</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <blockquote class="layui-elem-quote layui-quote-nm">
                            <form class="layui-form layui-col-space5" onsubmit="return false;">
                                <div class="layui-input-inline layui-show-xs-block">


                                    <select name="teacher_id" id="teacher_id" lay-reqText="教师必须填写" lay-search="">
                                        <option value="">直接选择或搜索教师</option>
                                        {foreach $teacher_arr as $key=>$vo }
                                        <option value="{$vo.id}">{$vo.teacher_name}</option>
                                        {/foreach}

                                    </select>
                                </div>

                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="grade_id" id="grade_id" lay-filter="grade_id" lay-search="">
                                        <option value="">直接选择或搜索年级</option>
                                        {foreach $grade_arr as $key=>$vo }
                                        <option value="{$vo.id}">{$vo.name}</option>
                                        {/foreach}

                                    </select>

                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="class_id" id="class_id" lay-reqText="班级必须填写">
                                        <option value="">班级选择，请先选择年级</option>


                                    </select>

                                </div>

                                <div class="layui-input-inline layui-show-xs-block">


                                    <select name="subject_id" id="subject_id" lay-search="">
                                        <option value="">直接选择或搜索学科</option>
                                        {foreach $sub_arr as $key=>$vo }
                                        <option value="{$vo.id}">{$vo.name}</option>
                                        {/foreach}

                                    </select>


                                </div>


                                <div class="layui-input-inline layui-show-xs-block">

                                    <input class="layui-input" lay-reqText="请输入整数" lay-verify="" placeholder="请输入节次"
                                        name="section_num" id="section_num">


                                </div>


                                <div class="layui-input-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="sreach">查询</button>
                                    <button class="layui-btn  layui-btn-primary"
                                        onclick="location.reload();return false;">
                                        重置
                                    </button>
                                </div>
                            </form>
                        </blockquote>
                        <table class="layui-hide" id="test" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var url = "__STATIC__/admin/";
        var form;
        layui.extend({
            notice: 'notice/notice'
        }).use(['laydate', 'table', 'form','util', 'notice'], function () {
            var table = layui.table;
            var form = layui.form;
            var notice = layui.notice;
            var util = layui.util;
            var tableIns = table.render({
                id: 'testReload',
                elem: '#test',
                url: "{:url('lists')}",
                method: "POST",
                request: {
                    pageName: 'offset', //页码的参数名称，默认：page
                    limitName: 'limit' //每页数据量的参数名，默认：limit
                },
                cols: [
                    [{
                        field: 'student_name',
                        title: "姓名",
                    }, {
                        field: 'created_at',
                        title: "日期",
                        sort: true
                    }, {
                        field: 'class_name',
                        title: "所在班级",
                    }, {
                        field: 'building_name',
                        title: "所在楼栋",
                    }, {
                        field: 'classroom_name',
                        title: "上课教室",
                    },  {
                        field: 'section_num',
                        title: "节次",
                        sort: true
                    }, {
                        field: 'subject_name',
                        title: "学科",
                    }, {
                        field: 'teacher_name',
                        title: "任教老师",
                    }, {
                        field: 'cou_start_time',
                        title: "上课时间",
                        sort: true
                    }, {
                        field: 'cou_end_time',
                        title: "下课时间",
                        sort: true
                    }, {
                        field: 'att_time',
                        title: "签到时间",
                        templet: function(d) {
								var logoSrc = util.toDateString(d.att_time * 1000, "yyyy-MM-dd HH:mm:ss");
								return logoSrc;
						},
                        sort: true
                    },
                    {
                        field: 'att_status',
                        title: "签到状态",
                        templet: function(d) {
                            if(d.att_status == 1){
                                return "正常"
                            }else{
                                return "迟到"
                            }
								
						},
                    }]
                ],
                page: true
            });

            form.on('select(grade_id)', function (data) {

                $("#class_id").html('').html("<option value=''>班级选择，请先选择年级</option>");

                $.ajax({
                    url: "{:url('classes')}?id=" + data.value,
                    dataType: 'json',
                    async: true,
                    success: function (data) {
                        console.log(data.length);

                        var text = $("#grade_id option:selected").text();

                        if (data.length == 0)
                            $("#class_id").html("<option value=''>" + text + "下没有班级</option>");
                        else
                            $("#class_id").html("<option value=''>班级选择，请先选择年级</option>");

                        form.render('select'); //这个很重要
                        $.each(data, function (index, item) {
                            $('#class_id').append(new Option(item.name, item.id));//往下拉菜单里添加元素
                            form.render('select'); //这个很重要
                        })
                    }
                });

            });

            //搜索
            form.on('submit(sreach)', function (data) {
                //执行重载
                table.reload('testReload', {
                    method: "POST",
                    request: {
                        pageName: 'offset', //页码的参数名称，默认：page
                        limitName: 'limit' //每页数据量的参数名，默认：limit
                    },
                    where: {
                        class_id: data.field.class_id,
                        teacher_id: data.field.teacher_id,
                        subject_id: data.field.subject_id,
                        section_num: data.field.section_num,
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

        });



    </script>
</body>

</html>